package com.hdax.dm.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hdax.dm.common.vo.item.ItemDescVo;
import com.hdax.dm.dto.CommonResponse;
import com.hdax.dm.dto.item.FloorItemDto;
import com.hdax.dm.dto.item.ItemCommentDto;
import com.hdax.dm.dto.item.ItemDescDTO;
import com.hdax.dm.entity.item.DmItemComment;
import com.hdax.dm.entity.user.DmUser;
import com.hdax.dm.service.DmItemCommentService;
import com.hdax.dm.service.DmItemService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.lang.ref.PhantomReference;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(path = "/item")
public class ItemDescController {

    @Resource
    private DmItemService dmItemService;
    @Resource
    private DmItemCommentService dmItemCommentService;
    @Resource
    private RedisTemplate<String,String> redisTemplate;

    //商品详情
    @PostMapping(path = "/desc/getItems")
    public CommonResponse<ItemDescDTO> getItems(@RequestBody ItemDescVo itemDescVo){
        return dmItemService.getItems(itemDescVo.getId());
    }

    //剧评
    @PostMapping(path = "/desc/getComments")
    public CommonResponse<ItemCommentDto> getComments(@RequestBody ItemDescVo itemDescVo){
        return dmItemCommentService.getComments(itemDescVo.getId());
    }

    //热门推荐
    @PostMapping(path = "/desc/getRecommend")
    public CommonResponse<List<FloorItemDto>> getRecommend(@RequestBody Map<String,Long> params){
        return dmItemService.getRecommend(params.get("itemTypeId"));
    }

    //添加剧评
    @PostMapping(path = "/desc/permission/addComments")
    public CommonResponse<String> addComments(@RequestBody DmItemComment dmItemComment){
        return dmItemCommentService.addComments(dmItemComment);
    }
}
